package analysis;

import model.ApiConfigDataModel;
import model.ApiDataModel;
import model.TestResultAnalysisModel;
import tool.DataReplace;

import java.util.ArrayList;

/**
 * Created by yangxianming on 2015-06-17.
 * 分析类,通过对ResultAnalysis工作表中的expect字符串做初步的判断,然后给出如何调用具体的分析实现
 */
public class AnalysisMain {
    ArrayList<ApiDataModel> admList = null;
    ApiConfigDataModel acdm = null;

    public AnalysisMain(ArrayList<ApiDataModel> admList, ApiConfigDataModel acdm){
        this.admList = admList;
        this.acdm = acdm;
    }

    public void parse(){
        for (ApiDataModel adm:admList){
            for (TestResultAnalysisModel testResultAnalysisModel:adm.testResultAnalysisModelList){
                String expect = testResultAnalysisModel.expect;
                if (expect == null)
                    continue;

                if (expect.equals("true") || expect.equals("false")){
                    ImmediateSet immediateSet = new ImmediateSet(expect);
                    immediateSet.parseExpect(testResultAnalysisModel, acdm);
                }

                if (expect.contains("comparison-")){
                    expect = DataReplace.replace(acdm, expect);
                    ExpectComparison c = new ExpectComparison(expect);
                    c.parseExpect(testResultAnalysisModel, acdm);
                    testResultAnalysisModel.expect = expect;    //将替换后的数据放回数组对象
                }
            }
        }
    }
}
